package plus.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;
@Slf4j
@RestController
class EchoController {

    @RequestMapping("/list")
    public String list(){

        //TraceContext可以绑定key-value
        TraceContext.putCorrelation("name", "admin");
        Optional<String> op = TraceContext.getCorrelation("name");
        log.info("name = {} ", op.get());
        //获取跟踪的traceId
        String traceId = TraceContext.traceId();
        log.info("traceId = {} ", traceId);

        return "skywalking";
    }
}